#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: 高建平
# @description: 
#
import json
import time
from fastapi import FastAPI, Request,status
from fastapi.responses import JSONResponse
from loguru import logger
from app.exceptions.status import Status
from app.models.result import  Result


def middleware(app:FastAPI):
    
    @app.middleware("http")
    async def catch_exceptions_middleware(request: Request, call_next):
        try:
            return await call_next(request)
        except Exception as e:
            # you probably want some kind of logging here
            logger.exception(e)
            return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,content=Result(code=Status.HTTP_FAIL.code, message='系统异常').__dict__)
